<div id="priceopen">
	<div class="modal-header ui-draggable-handle">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
		<h4 class="modal-title" id="ntModalLabel1">{$title}</h4>
        <input type="hidden" name="" id="id" value="{$id|default=''}">
        <input type="hidden" name="" id="requestType" value="{$requestType|default=''}">
	</div>
	<div class="modal-body">
		<div class="row">
			<div class="col-md-12">
				<div class="alert alert-dismissable alert-info">
					<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
					<h4> 信息框 </h4>
					<p></p>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-1">代号<span class="required"></span></div>
			<div class="col-md-1">
				<input type="text" class="form-control" v-model="idcode">
			</div>
			<div class="col-md-1">名称<span class="required" ></span></div>
			<div class="col-md-6">
				<input type="text" class="form-control" v-model="Tname">
			</div>
			<div class="col-md-1">排序<span class="required"></span></div>
			<div class="col-md-2">
				<input type="number" class="form-control text-right" value="500" v-model="sort">
			</div>
		</div>

		<div class="row" style="padding-top:0.5rem">
			<div class="col-md-1">加成<span class="required"></span></div>
			<div class="col-md-3">
				<div class="input-group">
					<input type="number" class="form-control text-right" v-model="rate">
					<span class="input-group-addon">%</span>
				</div>
			</div>
			<div class="col-md-1">箱数<span class="required"></span></div>
			<div class="col-md-3">
				<div class="input-group">
					<input type="number" class="form-control text-right" v-model="moq">
					<span class="input-group-addon">CTN</span>
				</div>
			</div>
			<div class="col-md-1">折扣<span class="required"></span></div>
			<div class="col-md-3">
				<div class="input-group">
					<input type="number" class="form-control text-right" v-model="discount">
					<span class="input-group-addon">%</span>
				</div>
			</div>
		</div>
		<div class="row" style="padding-top: 0.5rem">
			<div class="col-md-6">
				<ul class="nav nav-tabs">
					<li class="active"><a href="#">授权部门</a></li>
				</ul>
			</div>
			<div class="col-md-6">
				<ul class="nav nav-tabs">
					<li class="active"><a href="#">授权职务</a></li>
				</ul>
			</div>
		</div>
		<div class="row">
			<div class="col-md-6">
				<div class="div-scroll" style="height: 26rem">
					<table class="table table-hover ntTable">
						<tbody>
							<tr v-for="(item,index) in department">
								<td><input type="checkbox" v-model="department[index].ischecked"></td>
								<td :style="{'padding-left':item.level*20+'px'}">{{item.langname}}</td>
							</tr>
							
						</tbody>
					</table>
				</div>
			</div>
			<div class="col-md-6">
				<div class="div-scroll" style="height: 26rem">
					<table class="table table-hover ntTable">
						<tbody>
							<tr v-for="(item,index) in position">
								<td><input type="checkbox" v-model="position[index].ischecked"></td>
								<td :style="{'padding-left':item.level*20+'px'}">{{item.langname}}</td>
							</tr>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	
	</div>
	<div class="modal-footer">
		<button type="button" class="btn btn-default" data-dismiss="modal" data-whatever="参数"><span class="glyphicon glyphicon-remove"></span>取消</button>
		<button type="button" class="btn btn-primary" style="padding-left:24px;padding-right:24px" @click="savefun"><span class="glyphicon glyphicon-floppy-disk"></span>保存</button>
	</div>
</div>
<script>
new Vue({
	el:'#priceopen',
	data:()=>({
		idcode:'',//代号
		Tname:'',//名称
		sort:100,//排序
		olddrank:'',
		rate:'',
		moq:'',
		discount:'',
		department:[],//授权部门
		position:[],//授权职务
	}),
	async mounted(){
		await this.getDop()
		await this.getRpm()
		if($('#requestType').val() == 'edit'){
			this.getedit()
		}
	},
	methods:{
		//获取授权部门
		getDop(){
			return new Promise((res,rej)=>{
				$.ajax({
					url:'/admin/price/getDepartment',
					type:'post',
					success:data=>{
						data=JSON.parse(data)
						this.department=data
						this.department.forEach(element => {
							element.ischecked=false
						});
						res()
					}
				})
			})
		},
		//获取授权职务
		getRpm(){
			return new Promise((res,rej)=>{
				$.ajax({
					url:'/admin/price/getPosition',
					type:'post',
					success:data=>{
						data=JSON.parse(data)
						this.position=data
						this.position.forEach(element => {
							element.ischecked=false
						});				
						res()	
					}
				})
			})
		},
		//提交
		savefun(){
			if($('#requestType').val() == 'add'){
				var url = "/admin/price/addpricetype?request=insert";
			}else{
				var url = "/admin/price/pricetypeedit?request=update&id="+$('#id').val();
			}
			$.ajax({
				url:url,
				type:'post',
				data:{
					code:this.idcode,
					name:this.Tname,
					drank:this.sort,
					olddrank:this.olddrank,
					department:this.department,
					position:this.position,
					rate:this.rate,
					moq:this.moq,
					discount:this.discount,
				},
				success:data=>{
					data=JSON.parse(data)	
					change_mes_type('.alert',data.status)
					if(data.status == 1){
						$('.alert').show()
						$('.alert p').html('*'+data.msg+'<br>')
						$('#delmodel').val('true')
						$('#price_type_Modal').modal('hide')
					}else{
						$('.modal-body .alert').show()
						$('.modal-body .alert p').html('*'+data.msg+'<br>')
					}   	
				}
			})
		},
		//获取编辑数据
		getedit(){
			$.ajax({
				url:"/admin/price/pricetypeedit?request=edit&id="+$('#id').val(),
				type:'post',
				success:data=>{
					data=JSON.parse(data)
					data.data.position_ids.forEach(item=>{
						this.position.forEach(element=>{
							if(element.id==item)
							element.ischecked=true
						})
					})
					data.data.department_ids.forEach(item=>{
						this.department.forEach(element=>{
							if(element.id==item)
							element.ischecked=true
						})
					})
					this.idcode = data.data.code
					this.Tname = data.data.name
					this.sort = data.data.drank
					this.olddrank = data.data.olddrank
					this.rate = data.data.rate
					this.moq = data.data.moq
					this.discount = data.data.discount
				}
			})
		}
	}
})
</script>
	